package com.imm.da.base

import android.app.Application
import android.util.Log
import com.bumptech.glide.Glide
import com.imm.da.APP_KEY
import com.imm.da.BuildConfig
import com.imm.da.PUBLIC_ID
import com.qweather.sdk.view.HeConfig

/**
 * <p>------------------------------------------------------
 * <p> Copyright (C) 2021 zhangmz, All rights reserved.
 * <p> If there is technical discussion, you can contact zhangmz90@foxmail.com
 * <p>------------------------------------------------------
 * <p> des
 * <p>
 *
 * @author Created by Administrator
 * @date on 2021 2021/11/14 11:54
 */
class BaseApplication : Application() {

    override fun onCreate() {
        super.onCreate()

        HeConfig.init(PUBLIC_ID, APP_KEY)
        if (BuildConfig.DEBUG){
            // 切换至开发版服务
            HeConfig.switchToDevService()
        }else {
            // 切换至商业版服务
            HeConfig.switchToBizService()
        }

        Log.e("onlineLive", "------------- BaseApplication -----------")


        if (BuildConfig.DEBUG) {
            //严苛模式，捕获应用的违例策略
//            StrictMode.setThreadPolicy(
//                StrictMode.ThreadPolicy.Builder().detectAll()
//                    .penaltyLog().penaltyDialog()
//                    .build()
//            )
//            StrictMode.setVmPolicy(
//                StrictMode.VmPolicy.Builder().detectAll().penaltyLog()
//                    .penaltyDeath().build()
//            )
        }
    }

    override fun onTerminate() {
        super.onTerminate()
    }

    override fun onTrimMemory(level: Int) {
        super.onTrimMemory(level)
        // TRIM_MEMORY_RUNNING_LOW 内存不足(后台进程不足5个)，并且该进程优先级比较高，需要清理内存(0.7f可自定义)
        // TRIM_MEMORY_UI_HIDDEN 用户点击home或者按返回使得app所有页面在后台
        if (level == TRIM_MEMORY_UI_HIDDEN) {
            Glide.get(this).clearMemory()
        }
        Glide.get(this).trimMemory(level)
    }

    override fun onLowMemory() {
        super.onLowMemory()
        Glide.get(this).clearMemory()
    }

}